package app

import (
	//	"fmt"
	"hblog/proj/app/mdl"
	"hotime"
	"strings"
	"time"
)

type BallCtr struct {
	hotime.Ctr
}

func (this *BallCtr) Test() {
	rich := mdl.Rich{}
	this.Display(0, rich.Lists(int64(0), "", true))
}

func (this *BallCtr) Get() {

	timestamp := time.Now().Unix()
	tm := time.Unix(timestamp, 0)
	ti := tm.Format("2006-01-02")
	isToday := true
	if this.Request.FormValue("date") != "" && this.Request.FormValue("date") != ti {
		ti = this.Request.FormValue("date")
		isToday = false
		tt, _ := time.Parse("2006-01-02", ti)
		timestamp = tt.Unix()
	}

	var balls []hotime.Map
	if this.Request.FormValue("type") == "0" {
		balls = mdl.GetBall(timestamp, ti, isToday)
	} else {
		rich := mdl.Rich{}
		balls = rich.Lists(timestamp, ti, isToday)
	}
	//格式化为字符串,tm为Time类型
	this.Display(0, balls)

}

//分析
func (this *BallCtr) Fenxi() {
	if strings.EqualFold(this.Request.FormValue("fid"), "") {
		this.Display(1, "没有详情id")
		return
	}
	var data []hotime.Map
	if this.Request.FormValue("type") == "0" {
		data = mdl.GetYazhi(this.Request.FormValue("fid"))
	} else {
		rich := mdl.Rich{}
		data = rich.Info(this.Request.FormValue("fid"))
	}

	//yuche:=mdl.Yuche{}

	this.Display(0, data)
}

//获取所有的数据
func (this *BallCtr) Pan() {
	db := this.Db
	data := db.Query("select * from pan")
	this.Display(0, data)
}

func (this *BallCtr) Updatepan() {
	db := this.Db
	var res hotime.Map
	data := db.Query("select * from pan where key=?", this.Request.FormValue("key"))
	j1 := this.Request.FormValue("j1")
	j2 := this.Request.FormValue("j2")
	j3 := this.Request.FormValue("j3")

	if data != nil && len(data) > 0 {
		res = data[0]
		if !strings.EqualFold("", j1) {
			res["j1"] = j1
		}
		if !strings.EqualFold("", j2) {
			res["j2"] = j2
		}
		if !strings.EqualFold("", j3) {
			res["j3"] = j3
		}
		db.Exec("update pan set j1=?,j2=?,j3=?", res["j1"], res["j2"], res["j3"])
	} else {
		res = hotime.Map{"key": this.Request.FormValue("key")}
		if !strings.EqualFold("", j1) {
			res["j1"] = j1
		}
		if !strings.EqualFold("", j2) {
			res["j2"] = j2
		}
		if !strings.EqualFold("", j3) {
			res["j3"] = j3
		}
		//db.Exec("update pan set j1=?,j2=?,j3=?",res["j1"],res["j2"],res["j3"])
		db.Insert("pan", res)
	}
	this.Display(0, "成功！")
}
